<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['wxgid']){
	$id=pdo_getcolumn('core_account_wxapp',array('id'=>$_RQ['wxgid'],'uniacid'=>$_SESSION['uniacid']),'plugin_key');
}
if(!$id){
	$id=intval($_RQ['id'])?:intval($_RQ['merchid']);
}
if($_RQ['op']=='list'){
	$id=$id?:$_SESSION['merchid'];
	if(!$id){
		$store=pdo_get('jy_merch_user',array('status'=>1,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$store=pdo_get('jy_merch_user',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	//如果场景体自定义了店铺页面
	if($_SESSION['current_plugin'] && $_SESSION['current_plugin']!='core' && $_SESSION['current_plugin']!='jy_weishop'){
			$success_url=plugin($_SESSION['current_plugin'])->merch_shop;
			if($success_url){
				$usernum = intval($_RQ['usernum']);
				$tableid = intval($_RQ['tableid']);
				exi('','',$_SESSION['current_plugin'].$success_url.'/id='.$store['id'].'&tableid='.$tableid.'&usernum='.$usernum);
			}
	}
	if($store['id']){
		$_SESSION['merchid']=$store['id'];
	}
	model('jy_weishop/member')->checklogin('','','',$store['id']);
	model('jy_merch/member')->up_catefans($store['id']);
	model('jy_merch/member')->up_addmember($store['id']);
	$return['merchmember']=pdo_get('jy_merch_member',array('merchid'=>$store['id'],'mid'=>$_SESSION['uid']));
	$return['member']=cfc('core')->member_show($_SESSION['uid']);
	$return['goodsnum']=pdo_count('jy_weishop_goods',array('merchid'=>$id));
	$return['ordernum']=pdo_count('jy_weishop_order',array('merchid'=>$id));
	$store['address2']=$store['address'];
	//$store['address']=$store['address']?cfc('tools')->substr($store['address'],0,16).'****':'无地址';
	$store['address']=$store['address']?:'无地址';
	$store['mobile2']=$store['mobile'];
	$store['mobile']=$store['mobile']?cfc('tools')->substr($store['mobile'],0,7).'****':'无电话';
	$store['realname']=$store['realname']?cfc('tools')->substr($store['realname'],0,1).'***':'无';
	$store['lat_lng']=json_decode($store['lat_lng'],true);
	$store['pingjianum']=pdo_count('jy_merch_comments',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$store['id']),'id');
	$store['grouptitle']=pdo_getcolumn('jy_merch_category',array('uniacid'=>$_SESSION['uniacid'],'id'=>$store['cateid']),'catename');
	$store['islike']=pdo_getcolumn('jy_merch_like_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'merchid'=>$store['id']),'id');
	$store['islike']=$store['islike']?1:0;
	$store['topimg']=tomedia($store['topimg']);
	$store['pcd']=json_decode($store['pcd'],true);
	$store['address']=$store['pcd']['city'].' '.$store['pcd']['district'].' '.$store['pcd']['street'].' '.$store['address'];
	$return['store']=$store;
	if($store['yuyue_type']!='no' && $store['yuyue_type']){
		$return['params']=array('order'=>'goods','merchid'=>$id);
	}else{
		$return['params']=array('order'=>'goods','merchid'=>$id);
	}
	$pindex = max(1, 1);
	$psize = 12;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'nochecked'=>0,'merchid'=>$store['id'],'type <>'=>4);
	$fields=array('id','title','price','image','unit','originalprice','nochecked');
	$goods=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','salenum desc, id desc');
	foreach($goods as &$gv){
		$gv['image']=tomedia($gv['image']);
		$gv['originalprice']=$gv['originalprice']?:$gv['price']*1.2;
			$gv['originalprice']=price($gv['originalprice']);
			$v['tags']=pdo_getcolumn('jy_weishop_goods_comments',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$gv['id']),'tags');
	}
	$return['tuigoods']=$goods;
	$return['nowh'] = intval(date('H'));
	$return['id']=$id;
	$tableid = intval($_RQ['tableid'])?:$order['tableid'];
	if($tableid){
		$this->session('tableid',$tableid);
	}else{
		$tableid=$this->session('tableid');
	}
	if($tableid){
		$return['table'] = pdo_get('jy_weishop_table',array('merchid'=>$myshop['id'],'uniacid'=>$_SESSION['uniacid'],'id'=>$tableid));
	}
	$return['pluginset']['merchfooternav']=model('jy_merch/diy')->merchfooternav($_SESSION['merchid'],$return['pluginset']);
	$title=$store['merchname'];
	$desc=$store['desc'];
	$logo=$store['logo'];
	$sharelink='jy_merchcmi/index//id='.$_SESSION['merchid'].'&fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>$title?:'商户信息-商城',
			'desc'=>$desc?:'商户信息！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>tomedia($logo),
	);
	set_html('title',$title?:'商户信息');
	exi($return);
}

?>